package Reflex;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.Field;

public class ObjectFrame {
    @Test
    public static void saveObejct(Object obj) throws Exception {
        PrintStream ps = new PrintStream("fanqinyu");
        //给任意对象
        Class c = obj.getClass();
        String name = c.getSimpleName();//知道类名
        ps.println("----------" + name);

        Field[] fields = c.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            ps.println(field.getName());
            ps.println(field.get(obj));
            //名称和内容
        }
    ps.close();
    }

}
